﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WinForms = System.Windows.Forms;
using System.ComponentModel;
using ModernWSPView.Classes;

namespace ModernWSPView.Pages
{
    /// <summary>
    /// Interaction logic for PageSetXmlDataSource.xaml
    /// </summary>
    public partial class PageSetXmlDataSource : UserControl, INotifyPropertyChanged
    {
        public string SourceFileName { get; set; }

        public PageSetXmlDataSource()
        {
            InitializeComponent();
            this.DataContext = this;
        }

        private void OnSelectFile(object sender, RoutedEventArgs e)
        {
            WinForms.OpenFileDialog dlg = new WinForms.OpenFileDialog();
            if (dlg.ShowDialog() == WinForms.DialogResult.OK)
            {
                SetXmlSource(dlg.FileName);
            }
        }

        private void SetXmlSource(string xmlFilePath)
        {
            SourceFileName = xmlFilePath;
            AppModel.AppXmlDataSource.Source = new Uri(SourceFileName, UriKind.Absolute);
            OnPropertyChanged("SourceFileName");
        }

        private void OnFileDrop(object sender, DragEventArgs e)
        {
            string fileDroped = DropManager.GetDroppedFilename(e.Data);
            SetXmlSource(fileDroped);
        }

        public event PropertyChangedEventHandler PropertyChanged;

        public void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}
